home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 3: Developer Tools / Linux Cubed Series 3 - Developer Tools.iso / devel / db / esm-3.1 / esm-3 / usr / local / sm / src / include / LHINDPAGE.h < prev    next >
Encoding:
C/C++ Source or Header  |  1996-05-05  |  12.4 KB  |  397 lines

  1. #ifndef __LHINDPAGE_H__
  2. #define __LHINDPAGE_H__
  3.  
  4. /*
  5.  *    $RCSfile: LHINDPAGE.h,v $
  6.  *    $Revision: 1.1.1.1 $
  7.  *    $Date: 1996/05/04 21:55:07 $
  8.  */
  9. /**********************************************************************
  10. * EXODUS Database Toolkit Software
  11. * Copyright (c) 1991 Computer Sciences Department, University of
  12. *                    Wisconsin -- Madison
  13. * All Rights Reserved.
  14. *
  15. * Permission to use, copy, modify and distribute this software and its
  16. * documentation is hereby granted, provided that both the copyright
  17. * notice and this permission notice appear in all copies of the
  18. * software, derivative works or modified versions, and any portions
  19. * thereof, and that both notices appear in supporting documentation.
  20. *
  21. * THE COMPUTER SCIENCES DEPARTMENT OF THE UNIVERSITY OF WISCONSIN --
  22. * MADISON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS" CONDITION.  
  23. * THE DEPARTMENT DISCLAIMS ANY LIABILITY OF ANY KIND FOR ANY DAMAGES
  24. * WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
  25. *
  26. * The EXODUS Project Group requests users of this software to return 
  27. * any improvements or extensions that they make to:
  28. *
  29. *   EXODUS Project Group 
  30. *     c/o David J. DeWitt and Michael J. Carey
  31. *   Computer Sciences Department
  32. *   University of Wisconsin -- Madison
  33. *   Madison, WI 53706
  34. *
  35. *     or exodus@cs.wisc.edu
  36. *
  37. * In addition, the EXODUS Project Group requests that users grant the 
  38. * Computer Sciences Department rights to redistribute these changes.
  39. **********************************************************************/
  40. #include "lh_extfuncs.h"  
  41.  
  42. /*
  43.  *    Size of a LHINDPAGE defined in object.h
  44.  */
  45.  
  46. #ifdef __cplusplus            /* LHINDPAGE defs for C++ only */
  47.  
  48. //
  49. //    LH_TRACE macro                   
  50. //
  51. #ifdef LH_DEBUG
  52. #define LH_TRACE(x)    printf x
  53. #define BT_TRACE(x)    printf x
  54. #else
  55. #define LH_TRACE(x)
  56. #endif
  57.  
  58. enum LH_OPER  {
  59.     LH_READ = 1,
  60.     LH_INSERT = 2,
  61.     LH_DELETE = 4,
  62.     LH_INSERT_DELETE = 6
  63.     };
  64.  
  65.  
  66. // 
  67. //    LHINDEX page control structure 
  68. //
  69. struct LHINDCONTROL { 
  70.     LRC            lrc;            // for recovery (MUST BE 1st FIELD (cheated))
  71.     PID            selfID;            // id of this page
  72.     FOUR        selfInd;        // index value of this page 
  73.     TWO         endData;        // offset to the end of the data section
  74.     TWO         numOffsets;     // number of offsets
  75.     TWO         numFree;        // number of free bytes
  76.     ONE         selfOv;            // flag indicating this page is overflow bucket
  77.     ONE         nextOv;            // flag indicating next chained overflow bucket
  78.     SHORTPID    ovbId;          // id of next overflow bucket
  79.     float       load;            // load of current index page
  80.     ONE         type;           // SMDATATYPE
  81.     };
  82.  
  83.  
  84.  
  85. const LHIND_MAGIC = 14021967;   // change
  86.  
  87. //
  88. //     LHINDEX page definition
  89. //
  90. const LH_DATASIZE = BTREE_PAGESIZE - sizeof(LHINDCONTROL);
  91.  
  92. class LHINDPAGE {
  93.     
  94.     // 
  95.     //    Physical undos and redos must access page directly
  96.     //
  97.     friend void undoLHash_fr(LOGRECORDHDR*);
  98.     friend void redoLHash_fr(LOGRECORDHDR*);
  99.  
  100.         LHINDCONTROL    lhCtrl;                        // control information
  101.         char            data[LH_DATASIZE - sizeof(SLOT)];
  102.         SLOT            slot[1];                    // first slot on page
  103.  
  104.         //
  105.         //    Compress to minimize fragmentation
  106.         //
  107.         void        Compress();
  108.  
  109.     public:
  110.         //
  111.         //    General queries
  112.         //
  113.         PID&        SelfID()        { return lhCtrl.selfID; }
  114.         int            Volume()        { return lhCtrl.selfID.volid; }
  115.         int            NumSlots()        { return lhCtrl.numOffsets; }
  116.         SMDATATYPE    KeyType()        { return (SMDATATYPE) lhCtrl.type; }
  117.         FOUR        SelfInd()        { return lhCtrl.selfInd; }
  118.         int            OvLabel()        { return lhCtrl.selfOv; }
  119.         int            HaveOv()        { return lhCtrl.nextOv; }
  120.         SHORTPID    OvPage()        { return lhCtrl.ovbId; }
  121.         float        Load()            { return lhCtrl.load; }
  122.  
  123.         //
  124.         //    set overflow flag
  125.         //
  126.         void        SetPageOverflow(SHORTPID& ovPid)    {
  127.                         lhCtrl.nextOv = TRUE;
  128.                         lhCtrl.ovbId = ovPid;
  129.                         }
  130.         //
  131.         //    reset overflow flag
  132.         //
  133.         void        ResetPageOverflow(int keepFlag)    {
  134.                         lhCtrl.nextOv = FALSE;
  135.                         if (!keepFlag)
  136.                             lhCtrl.ovbId = NULLPID;
  137.                         }
  138.         
  139.         //
  140.         //    Space usage 
  141.         //
  142.         int            UsableSpace()    { 
  143.                         return LH_DATASIZE - lhCtrl.endData 
  144.                                 - (lhCtrl.numOffsets * sizeof(slot[0]));
  145.                         }
  146.         int            UsedSpace()        { return LH_DATASIZE - lhCtrl.numFree; }
  147.         int            FreeSpace()        { return lhCtrl.numFree; }
  148.  
  149.         //
  150.         //    LRC 
  151.         //
  152.         LRC&        lrc()            { return lhCtrl.lrc; }
  153.  
  154.         //
  155.         //    Return TRUE if this page is safe
  156.         //
  157.         int            IsSafe(LH_OPER oper, int maxKeyLen);
  158.  
  159.         //
  160.         //    Return a reference to tuple in slot sNum
  161.         //
  162.         BT_Tuple&    Tuple(int sNum);
  163.  
  164.         //
  165.         //    Add/Remove an element to/from slot sNum
  166.         //
  167.         int         AddElem(int sNum, void* const elem);
  168.         int         RemoveElem(int sNum, void* const elem);
  169.  
  170.  
  171.         //
  172.         //    Search for keyVal and, if found, return the slot in retSlot.
  173.         //    Returns TRUE if found, FALSE otherwise.
  174.         //
  175.         int         Search(int keyLen, void* keyVal, 
  176.                                         PFC compFunc, TWO& retSlot);
  177.  
  178.         //
  179.         //    Insert/Remove a tuple into/from slot "slotNum"
  180.         //
  181.         void        InsertTuple(BT_Tuple& const tuple, int slotNum);
  182.         void        RemoveTuple(int slotNum);
  183.  
  184.         //
  185.         //    Move numTuples starting at slotNum to destSlot in destPage
  186.         //
  187.         void        ShiftTuple(int slotNum, LHINDPAGE* destPage, 
  188.                                         int destSlot, int numTuples);
  189.  
  190.         //
  191.         //    Set tuple to overflow (reclaim space used by oidList)
  192.         //
  193.         void        SetOverflow(int slotNum, PID& const ovPid);
  194.         
  195.         //
  196.         //    Set tuple to underflow (reinsert oidList)
  197.         //
  198.         void        SetUnderflow(int slotNum, int oidCnt, void* const elList);
  199.  
  200.         //
  201.         //    Copy data and data usage indicators to target page
  202.         //
  203.         void         CopyData(LHINDPAGE* target)    {
  204.                                 bcopy(data, target->data, LH_DATASIZE);
  205.                                 target->lhCtrl.endData = lhCtrl.endData;
  206.                                 target->lhCtrl.numOffsets = lhCtrl.numOffsets;
  207.                                 target->lhCtrl.numFree = lhCtrl.numFree;
  208.                                 target->lhCtrl.ovbId = lhCtrl.ovbId;
  209.                                 target->lhCtrl.load = lhCtrl.load;
  210.                                 }
  211.  
  212.         //
  213.         //    Initialize a new page
  214.         //
  215.         void         Init(PID& const pid, FOUR hashval, SMDATATYPE keyType,
  216.                                     int ovFlag) {
  217.                                 lhCtrl.endData = lhCtrl.numOffsets = 0;
  218.                                 lhCtrl.numFree = LH_DATASIZE;
  219.                                 lhCtrl.selfID = pid;
  220.                                 lhCtrl.selfInd = hashval;
  221.                                 lhCtrl.type = keyType;
  222.                                 lhCtrl.ovbId = NULLPID;
  223.                                 lhCtrl.nextOv = FALSE;
  224.                                 lhCtrl.selfOv = ovFlag;
  225.                                 lhCtrl.load = 0.0;
  226.                                 }
  227.  
  228.         //
  229.         //    calculate current load of this page
  230.         //
  231.         float         LoadComp();
  232.  
  233.         //
  234.         //    set current load of this page
  235.         //
  236.         void         SetLoad(float load) {
  237.                             lhCtrl.load = load;
  238.                             }
  239.         
  240.         //
  241.         //    convert overlow pages
  242.         //
  243.         void     OvConvert(FOUR hashVal, BOOL convert) {
  244.                             lhCtrl.selfInd = hashVal;
  245.                             lhCtrl.selfOv = !convert;
  246.                             }
  247.         //
  248.         //    Debugging utilities
  249.         //
  250.         int          CheckContent();
  251.         void        Print(BUFGROUP* bufGroup);
  252.     };
  253.  
  254. #if (defined DEBUG && defined lhash_MODULE) || ! defined DEBUG
  255.  
  256. INLINE BT_Tuple& LHINDPAGE::Tuple(int sNum)
  257. {
  258.     return *((BT_Tuple*)(data+slot[-sNum]));
  259. }
  260.  
  261. #endif /* (DEBUG && lhash_MODULE) || !DEBUG */
  262.  
  263.  
  264.  
  265. class LHashStack;
  266. class LH_SMOPages;
  267.  
  268.  
  269. extern "C"  {
  270.     extern int LH_AllocDirPage(TID tid, int volume, BUFGROUP* bufGroup,
  271.                             PID& returnPid, int rootFlag, SMDATATYPE keyType);
  272.     extern int LH_AllocPage(TID tid, int volume, BUFGROUP* bufGroup,
  273.                             PID& returnPid, FOUR hashVal, SMDATATYPE keyType,
  274.                             int ovFlag);
  275.     extern int LH_DirSearch(PID& const rootPid, int keyLen, void* keyVal,
  276.                             LHashStack& dirPl, SHORTPID& indPid, LH_OPER oper);
  277.     extern int LH_DirSplit(TID tid, int volume, BUFGROUP* bufGroup,
  278.                             LHashStack& dirPl, LH_SMOPages& smo,
  279.                             PageDesc& dirPd, SHORTPID& const indPid);
  280.     extern int LH_DirSplitUpdate(TID tid, int volume, BUFGROUP* bufGroup,
  281.                             LHashStack& dirPl, SHORTPID& const indPid,
  282.                             LH_SMOPages& smo, float oldFromLoad,
  283.                             float fromLoad, float toLoad);
  284.     extern int LH_IndSearch(PID& const indPid, int keyLen, void* keyVal, 
  285.                             PageDesc& curPd, LHashStack& curPl, int& found,
  286.                             TWO& returnSlot, LH_OPER oper, PFC compFunc);
  287.     extern int LH_SplitPage(TID tid, LHashStack& dirPl, BUFGROUP* bufGroup, 
  288.                             LH_SMOPages& smo, LHashStack& fromPl, 
  289.                             LHashStack& toPl, PFC CompFunc);
  290.     extern int LH_InsertNewTuple(TID tid, BUFGROUP* bufGroup, LHashStack& curPl,
  291.                             PageDesc& curPd, TWO& slot, BT_Tuple& const tuple,
  292.                             PFC compFunc);
  293.     extern int LH_NewElem(TID tid, BUFGROUP* bufGroup, PID& const dirPid,
  294.                             LHashStack& curPl, int keyLen, void* keyVal, 
  295.                             TWO elSize, void* const newElem, 
  296.                             int maxKeyLen, PFC compFunc);
  297.     extern int LH_DecrElCnt(TID tid, PID& const rootPid, BUFGROUP* bufGroup,
  298.                             void* key, int keyLen,
  299.                             int maxKeyLen, PFC compFunc);
  300.     extern int LH_IncrElCnt(TID tid, PID& const rootPid, BUFGROUP* bufGroup,
  301.                            void* key, int keyLen,
  302.                            int maxKeyLen, PFC compFunc);
  303.     extern int LH_SetOverflow(TID tid, PID& const rootPid,
  304.                             BUFGROUP* bufGroup,
  305.                                void* key, int keyLen,
  306.                                int maxKeyLen, PFC compFunc,
  307.                                void* const elList, int elSize, int numEl);
  308.     extern int LH_ResetOverflow(TID tid, PID& const rootPid,
  309.                             BUFGROUP* bufGroup,
  310.                             void* key, int keyLen,
  311.                             int maxKeyLen, PFC compFunc,
  312.                                void* const elList, int numOid);
  313.  
  314.     extern void LH_LogDirPageInit(PAGEHASH* pHash, int rootFlag,
  315.                                     SMDATATYPE keyType);
  316.     extern void LH_LogIndexPageInit(PAGEHASH* pHash, SMDATATYPE keyType,
  317.                             FOUR hashVal, int ovFlag);
  318.     extern void LH_LogLogicInsert(PID& pid, PAGEHASH* pHash, LRC& lrc,
  319.                             PID& const rootPid, void* const key, 
  320.                             TWO keyLen, void* const el, TWO elSize, 
  321.                             TWO maxKeyLen, TWO unique, SMDATATYPE keyType,
  322.                             BOOL primary);
  323.     extern void LH_LogLogicDelete(PID& pid, PAGEHASH* pHash, LRC& lrc,
  324.                             PID& const rootPid, void* const key, 
  325.                             TWO keyLen, void* const el, TWO elSize, 
  326.                             TWO maxKeyLen, TWO unique, SMDATATYPE keyType,
  327.                             BOOL primary);
  328.     extern void LH_LogSetIndexOverflow(PID& pid, PAGEHASH* pHash, LRC& lrc,
  329.                             SHORTPID newOvPage, 
  330.                             SHORTPID oldOvPage);
  331.     extern void LH_LogResetIndexOverflow(PID& pid, PAGEHASH* pHash, LRC& lrc,
  332.                             SHORTPID oldOvPage, int keepFlag);
  333.     extern void LH_LogDirUpdate(PID& pid, PAGEHASH* pHash, LRC& lrc,
  334.                              float oldFromLoad, float fromLoad, 
  335.                              float toLoad, BOOL growFlag);
  336.     extern void LH_LogDirSetNextEntry(PID& pid, PAGEHASH* pHash, LRC& lrc,
  337.                              SHORTPID newPage, FOUR hashVal);
  338.     extern void LH_LogDirRootCtrl(PID& pid, PAGEHASH* pHash, LRC& lrc, 
  339.                              int undoFlag);
  340.     extern void LH_LogDirSplitCopy(PID& pid, PAGEHASH* pHash, LRC& lrc,
  341.                              int height, int curPos);
  342.     extern void LH_LogDirSplitReset(PID& pid, PAGEHASH* pHash, LRC& lrc,
  343.                              SHORTPID page1, SHORTPID page2,
  344.                              LHDIRPAGE* newp);
  345.     extern void LH_LogLogicIncrElCnt(PID& pid, PAGEHASH* pHash, LRC& lrc,
  346.                              PID& const rootPid, void* const key,
  347.                              TWO keyLen, TWO maxKeyLen, SMDATATYPE keyType);
  348.     extern void LH_LogLogicDecrElCnt(PID& pid, PAGEHASH* pHash, LRC& lrc,
  349.                                 PID& const rootPid, void* const key,
  350.                              TWO keyLen, TWO maxKeyLen, SMDATATYPE keyType);
  351.     extern void LH_LogLogicSetOverflow(PID& pid, PAGEHASH* pHash, LRC& lrc,
  352.                 PID& const rootPid, void* const key, TWO keyLen, TWO maxKeyLen,
  353.                 SMDATATYPE keyType, int numEl, int elSize, void* const elList,
  354.                 PID& const ovPid);
  355.     extern void LH_LogLogicResetOverflow(PID& pid, PAGEHASH* pHash, LRC& lrc,
  356.                 PID& const rootPid, void* const key, TWO keyLen, TWO maxKeyLen,
  357.                 SMDATATYPE keyType, int numEl, int elSize, void* const elList,
  358.                 PID& const ovPid);
  359.     extern void LH_LogOvConvert(PID& pid, PAGEHASH* pHash, LRC& lrc,
  360.                 FOUR oldHashVal, FOUR newHashVal, BOOL cvtFlag);
  361.     extern void LH_LogSetThreshold(PID& pid, PAGEHASH* pHash, LRC& lrc,
  362.                              float oldThreshold, float newThreshold);
  363.  
  364. #ifdef SERVER_MAKE
  365.     extern void LH_LogPureCLR(LSNOFFSET);
  366. #endif
  367. }
  368.  
  369.  
  370. #ifdef SERVER_MAKE
  371.     extern void LH_LogPhysicInsert(PID&, PAGEHASH*, LRC&,
  372.                         TWO, TWO, int, void*);
  373.     extern void LH_LogPhysicDelete(PID&, PAGEHASH*, LRC&, 
  374.                         TWO, TWO, int, void*);
  375.     extern void LH_LogPhyLogInsert(PID&, PAGEHASH*, LRC&,
  376.                         TWO, int, void*);
  377.     extern void LH_LogPhyLogDelete(PID&, PAGEHASH*, LRC&, 
  378.                         TWO, int, void*);
  379. #endif
  380.     extern void LH_LogPhysicInsert(PID& pid, PAGEHASH* pHash, LRC& lrc,
  381.                                     TWO slotNum, TWO numSlot);
  382.     extern void LH_LogPhyLogInsert(PID& pid, PAGEHASH* pHash, LHINDPAGE* indp,
  383.                                     LRC& lrc, TWO numSlot);
  384.     extern void LH_LogPhysicDelete(PID& pid, PAGEHASH* pHash, LRC& lrc,
  385.                                     TWO slotNum, TWO numSlot);
  386.     extern void LH_LogPhyLogDelete(PID& pid, PAGEHASH* pHash, LHINDPAGE* indp,
  387.                                     LRC& lrc, TWO numSlot);
  388.     extern void LH_LogDirLoadUpdate(PID& pid, PAGEHASH* pHash, LRC& lrc,
  389.                              float load1, float load2);
  390.     extern void LH_LogDirLoadUpdate(PID&, PAGEHASH*, LRC&,
  391.                         float);
  392. #endif        /* #ifdef C++ */
  393.  
  394. #endif __LHINDPAGE_H__
  395.  
  396.  
  397.